﻿
using GlobalObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
//using WCFServiceWebRole1.CorsSupport;
using WCFServiceWebRole1.DataObjects;

namespace WCFServiceWebRole1.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "Iuser" in both code and config file together.
    [ServiceContract]
    public interface Iusers
    {
        #region Website Management

        [OperationContract]
        [WebInvoke(Method="POST",
            RequestFormat=WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "contactus")]
        [Description("Adds contactus details")]
        string addcontactus(ContactUs data);

        [OperationContract]
        [WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "testimonial")]
        [Description("Adds a testimonial")]
        string addTestimonial(Testimonial data);

        [OperationContract]
        [WebInvoke(Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "testimonial")]
        [Description("Gets all the testimonials")]
        List<Testimonial> getTestimonials();

        [OperationContract]
        [WebInvoke(Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "publicdevices/{userid}")]
        [Description("Gets all the authorized devices")]
        DeviceDiscovery getAllDevices(string userid);

        [OperationContract]
        [WebInvoke(Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "configfile?userid={userid}&deviceid={deviceid}")]
        [Description("Gets the xml configuration file")]
        Stream getConfigFile(int userid,int deviceid);

        #endregion

        #region User

        //Get the details of a user with username
        [OperationContract]
        [WebGet(
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user/{userid}")]
        [Description("Gets the details of a user")]
        UserDetailsResponse getUserByUserId(string userid);

        //Checking uniqueness of username
        [OperationContract]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "users/checkusername/{username}")]
        [Description("Checks if unique username is available")]
        bool CheckUserName(string username);

        //Change Password 
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user/changepassword/{userid}")]
        [Description("Changes user password")]
        bool ChangePassword(string userid, ChangePasswordContract user);

        //Get the details of a user with username
        [OperationContract]
        [WebInvoke(Method="POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user/login")]
        UserDetailsResponse checkLogin(UserLoginContract credentials);

        //Add a new user
        [OperationContract]
        [WebInvoke(Method = "POST",
            //BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user")]
        [Description("Adds a user")]
        UserDetailsResponse addUser(User user);

        //update existing user details
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user/update/{userid}")]
        [Description("Updates a user")]
        UserDetailsResponse updateUser(string userid, UserDetails user);

        //Remove a user
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "user/delete/{userid}")]
        [Description("Deletes a user")]
        bool deleteUser(string userid, UserDeleteContract user);

        #endregion

        #region Devices


        // Change the repository of the device
        [OperationContract]
        [WebInvoke(Method ="POST",BodyStyle= WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "customrepo/device/{deviceid}")]
        [Description("Change the repository to store data")]
        string changeRepository(string deviceid, CustomRepo repoinfo);

        // Change the repository of the device
        [OperationContract]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "customrepo/device/{deviceid}")]
        [Description("gets the repository where data is stored")]
        CustomRepo getRepository(string deviceid);

        // Get the list of device associated with a user
        [OperationContract]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "devices/list?userid={userid}&privacy={privacy}")]
        [Description("Gets a list of all devices for given userid")]
        List<DeviceDetailsResponse> getDevicesList(string userid,string privacy);

        //Get details of a device
        [OperationContract]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            // UriTemplate = "devices/device?userid={userid}&deviceid={deviceid}")]
            UriTemplate = "devices?userid={userid}&deviceid={deviceid}")]
        [Description("Gets the specified device provided a valid userid of who is accessing it")]
        DeviceDetailsResponse getDevice(int userid, int deviceid);

        //Check whether a device name already exist
        [OperationContract]
        [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "devices/checkdevicename?userid={userid}&devicename={devicename}")]
        [Description("Checks if a devicename is unique")]
        bool checkDeviceName(int userid, string devicename);

        //Add a device
        [OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "devices")]
        [Description("Adds a device")]
        DeviceDetailsResponse addDevice(Device device);

        //update existing user details
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "devices/update/{deviceid}")]
        [Description("Updates a device")]
        DeviceDetailsResponse updateDevice(string deviceid, Device device);

        //Remove a device
        //Returns boolean true if operation is successful 
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "devices/delete/{deviceid}")]
        [Description("Deletes a device")]
        bool deleteDevice(String deviceid);

        #endregion

        #region Shared Devices

        [OperationContract]
        [WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sharedevice/{deviceid}")]
        [Description("Adds a private device to be shared with another user")]
        bool sharePrivateDevice(string deviceid,ShareDeviceContract shareinfo);

        [OperationContract]
        [WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sharedevice/delete/{deviceid}")]
        [Description("Delets a private device shared with another user")]
        bool removeSharedPrivateDevice(string deviceid, ShareDeviceContract shareinfo);



        #endregion

        #region Sensor
        // Get the list of sensors associated with a device
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            //RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensors?deviceid={deviceid}")]
        [Description("Gets a list of all sensors for given deviceid")]
        List<SensorResponse> getSensorsList(int deviceid);

        // Get the list of sensors associated with a device
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            //RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor")]
        [Description("Adds a sensor for given deviceid")]
        string addSensor(Sensor sensor);


        // Get information about a sensor by Id
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            //RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor/{sensorid}")]
        [Description("Gets the specified sensor")]
        SensorResponse getSensorsById(string sensorid);
        
        // Get the nearest sensors in the given radius 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "nearestsensots?userid={userid}&sensorid={sensorid}&radius={radius}")]
        [Description("Gets the list of nearest sensors within a given radius")]
        List<NearestSensorsResponse> getNearestSensors(int userid, int sensorid, double radius);

        // Set the trigger for a given sensor 
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor/{sensorid}/trigger")]
        [Description("Sets the trigger for a given sensor ")]
        string setTrigger(string sensorid,TriggerRequest trigger);

        
        // Set the trigger for a given sensor 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor/{sensorid}/trigger")]
        [Description("Sets the trigger for a given sensor ")]
        TriggerResponse getTrigger(string sensorid);

        #endregion

        #region PushNotification

        //Subscribe to a channel 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "subscribe?sensorid={sensorid}&userid={userid}")]
        [Description("Subscribe to a sensor by providing userid of who wants this subscription")]
        SubscriberResponse SubscribeChannel(string userid, string sensorid);

        //Subscribe to a channel 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "subscribe/missingdevice?deviceid={deviceid}&userid={userid}")]
        [Description("Subscribe to a sensor by providing userid of who wants this subscription")]
        SubscriberResponse SubscribeMissingChannel(string userid, string deviceid);


        //Get subscribers list to a sensor 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "subscriberslist?sensorid={sensorid}&userid={userid}")]
        [Description("Gets the list of all subscribed users for a sensor")]
        List<SubscribedUsers> SubscribedUsers(string userid, string sensorid);

        ////Get list of all subscribed sensors
        //[OperationContract]
        //[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
        //    RequestFormat = WebMessageFormat.Json,
        //    ResponseFormat = WebMessageFormat.Json,
        //    UriTemplate = "allsubscriberslist")]
        //List<int> allSubscribedSensors();

        //Unsubscribe
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "unsubscribe?sensorid={sensorid}&userid={userid}")]
        [Description("Unsubscribe from a sensor")]
        bool UnSubscribeChannel(string userid, string sensorid);

        #endregion

        #region Notification
        // Get the list of lost devices 
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "lostdevices/{userid}")]
        [Description("Get the list of lost devices")]
        List<NotificationResponse> getlostDevices(string userid);

        //Get all the notifications
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
          ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "notifications/{userid}")]
        [Description("Get the list of lost devices")]
        List<NotificationResponse> getNotification(string userid);

        //Get all the notifications
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
          ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "notifications/delete/{notificationId}")]
        [Description("Get the list of lost devices")]
        string removeNotification(string notificationId);


        #endregion
    }
}
